﻿// Decompiled with JetBrains decompiler
// Type: DynamicClipping.CUiDynDynamicClippingForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.ComponentModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DynamicClipping;

public class CUiDynDynamicClippingForm : TxForm
{
  private float m_initialClippingPlaneRatio;
  private IContainer components;
  private GroupBox groupBox1;
  private Label label3;
  private NumericUpDown _numericUpDownPlane;
  private Label label2;
  private Label label1;
  private TxTrackBar _trackBarPlane;
  private Button _buttonClose;
  private Button _buttonReset;

  public CUiDynDynamicClippingForm() => this.InitializeComponent();

  private void _buttonClose_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void CUiDynDynamicClippingForm_Load(object sender, EventArgs e)
  {
    TxApplicationModeEx applicationModeEx = new TxApplicationModeEx("DYNAMIC_CLIPPING_SETTINGS_MODE", true);
    if (!TxApplicationEx.IsInSpecificMode(applicationModeEx))
      TxApplicationEx.EnterMode(applicationModeEx);
    this.m_initialClippingPlaneRatio = TxApplication.ViewersManager.GraphicViewer.DynamicClipping.ClippingPlaneRatio * 100f;
    this.LoadConfiguration();
  }

  private void _trackBarPlane_ValueChanged(object sender, EventArgs e)
  {
    this._numericUpDownPlane.Value = Convert.ToDecimal(((TrackBar) this._trackBarPlane).Value);
  }

  private void _numericUpDownPlane_ValueChanged(object sender, EventArgs e)
  {
    ((TrackBar) this._trackBarPlane).Value = Convert.ToInt32(this._numericUpDownPlane.Value);
    this.UpdateClippingValue(((TrackBar) this._trackBarPlane).Value);
  }

  private void _numericUpDownPlane_KeyPress(object sender, KeyPressEventArgs e)
  {
    if (char.IsDigit(e.KeyChar))
    {
      if (this._numericUpDownPlane.Text.Length < 2 || !(this._numericUpDownPlane.Value != 10M) && e.KeyChar == '0')
        return;
      e.Handled = true;
    }
    else
    {
      if (e.KeyChar != '-')
        return;
      e.Handled = true;
    }
  }

  private void CUiDynDynamicClippingForm_FormClosed(object sender, FormClosedEventArgs e)
  {
    this.StoreConfiguration();
    TxApplicationModeEx applicationModeEx = new TxApplicationModeEx("DYNAMIC_CLIPPING_SETTINGS_MODE", true);
    if (!TxApplicationEx.IsInSpecificMode(applicationModeEx))
      return;
    TxApplicationEx.ExitMode(applicationModeEx);
  }

  private void StoreConfiguration()
  {
    CUiDynDynamicClippingApp.SetClippingPlaneRatio(((TrackBar) this._trackBarPlane).Value);
  }

  private void LoadConfiguration()
  {
    this._numericUpDownPlane.Value = (Decimal) Convert.ToInt32(this.m_initialClippingPlaneRatio);
  }

  private void _buttonReset_Click(object sender, EventArgs e)
  {
    this._numericUpDownPlane.Value = Convert.ToDecimal(this.m_initialClippingPlaneRatio);
  }

  private void UpdateClippingValue(int value)
  {
    float num = value != 0 ? (float) value / 100f : 1f / 1000f;
    foreach (TxGraphicViewer graphicViewer in TxApplication.ViewersManager.GraphicViewers)
      graphicViewer.DynamicClipping.ClippingPlaneRatio = num;
    TxApplication.RefreshDisplay();
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiDynDynamicClippingForm));
    this.groupBox1 = new GroupBox();
    this.label3 = new Label();
    this._numericUpDownPlane = new NumericUpDown();
    this.label2 = new Label();
    this.label1 = new Label();
    this._trackBarPlane = new TxTrackBar();
    this._buttonClose = new Button();
    this._buttonReset = new Button();
    this.groupBox1.SuspendLayout();
    this._numericUpDownPlane.BeginInit();
    ((ISupportInitialize) this._trackBarPlane).BeginInit();
    ((Control) this).SuspendLayout();
    this.groupBox1.Controls.Add((Control) this.label3);
    this.groupBox1.Controls.Add((Control) this._numericUpDownPlane);
    this.groupBox1.Controls.Add((Control) this.label2);
    this.groupBox1.Controls.Add((Control) this.label1);
    this.groupBox1.Controls.Add((Control) this._trackBarPlane);
    componentResourceManager.ApplyResources((object) this.groupBox1, "groupBox1");
    this.groupBox1.Name = "groupBox1";
    this.groupBox1.TabStop = false;
    componentResourceManager.ApplyResources((object) this.label3, "label3");
    this.label3.Name = "label3";
    componentResourceManager.ApplyResources((object) this._numericUpDownPlane, "_numericUpDownPlane");
    this._numericUpDownPlane.Name = "_numericUpDownPlane";
    this._numericUpDownPlane.Value = new Decimal(new int[4]
    {
      50,
      0,
      0,
      0
    });
    this._numericUpDownPlane.ValueChanged += new EventHandler(this._numericUpDownPlane_ValueChanged);
    this._numericUpDownPlane.KeyPress += new KeyPressEventHandler(this._numericUpDownPlane_KeyPress);
    componentResourceManager.ApplyResources((object) this.label2, "label2");
    this.label2.Name = "label2";
    componentResourceManager.ApplyResources((object) this.label1, "label1");
    this.label1.Name = "label1";
    componentResourceManager.ApplyResources((object) this._trackBarPlane, "_trackBarPlane");
    ((TrackBar) this._trackBarPlane).Maximum = 100;
    ((Control) this._trackBarPlane).Name = "_trackBarPlane";
    ((TrackBar) this._trackBarPlane).TickFrequency = 5;
    ((TrackBar) this._trackBarPlane).Value = 50;
    ((TrackBar) this._trackBarPlane).ValueChanged += new EventHandler(this._trackBarPlane_ValueChanged);
    this._buttonClose.DialogResult = DialogResult.Cancel;
    componentResourceManager.ApplyResources((object) this._buttonClose, "_buttonClose");
    this._buttonClose.Name = "_buttonClose";
    this._buttonClose.UseVisualStyleBackColor = true;
    this._buttonClose.Click += new EventHandler(this._buttonClose_Click);
    componentResourceManager.ApplyResources((object) this._buttonReset, "_buttonReset");
    this._buttonReset.Name = "_buttonReset";
    this._buttonReset.UseVisualStyleBackColor = true;
    this._buttonReset.Click += new EventHandler(this._buttonReset_Click);
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this._buttonClose;
    ((Control) this).Controls.Add((Control) this._buttonReset);
    ((Control) this).Controls.Add((Control) this.groupBox1);
    ((Control) this).Controls.Add((Control) this._buttonClose);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedSingle;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiDynDynamicClippingForm);
    this.ShouldCloseOnDocumentUnloading = true;
    ((Form) this).ShowIcon = false;
    ((Form) this).SizeGripStyle = SizeGripStyle.Hide;
    ((Form) this).FormClosed += new FormClosedEventHandler(this.CUiDynDynamicClippingForm_FormClosed);
    ((Form) this).Load += new EventHandler(this.CUiDynDynamicClippingForm_Load);
    this.groupBox1.ResumeLayout(false);
    this.groupBox1.PerformLayout();
    this._numericUpDownPlane.EndInit();
    ((ISupportInitialize) this._trackBarPlane).EndInit();
    ((Control) this).ResumeLayout(false);
  }
}
